<template>
    <div class="table-container">
      <div class="table-container__top">
        <div class="table-container__top--title">项目列表</div>
        <t-button theme="primary"  @click="goRoute('create')">
          <template #icon><add-icon /></template>
          新建项目
        </t-button>
      </div>
    <div class="table-border" v-if="tableData?.list?.length>0">
      <common-table :data="tableData"  :fromMenu = "1" @refresh-list="refresh"></common-table>
    </div>
    <div v-else class="table-container__empty">
        <img class="table-container__empty--img" src="@/assets/icons/svg/empty.svg" alt="">
        <div class="table-container__empty--text">暂无内容</div>
      </div>
    </div>
</template>
<script lang="jsx" setup>
import { useRouter } from 'vue-router';
import { AddIcon } from 'tdesign-icons-vue-next';
import CommonTable from '@/views/components/table/CommonTable.vue';
import { getAssessList } from "@/api/sjhg/assess";

const router = useRouter();
const goRoute = (path, id) =>{
          const query = {}
            if (id) {
              query.id = id
            }
            router.push({
              path: './' + path,
              query,
            })
}
//-------------------------接口------------------------------------
const tableData = ref({});

let params = {
  pageNum :1,
  pageSize : 10,
  status: 3,
  sortField: 'update_time',
  sortOrder: 'DESC',
}
const refresh = (changeParams) =>{
  if(changeParams?.pagination){ //分页
    params.pageNum = changeParams.pagination.current
    params.pageSize = changeParams.pagination.pageSize
  }else if(changeParams?.sorter){ //排序
    params.pageNum = 1
    params.sortOrder = changeParams?.sorter.descending ? 'DESC':'ASC'
    if(changeParams?.sorter.sortBy === 'approvalTime'){
      params.sortField = 'approval_time'
    }else if(changeParams?.sorter.sortBy === 'submitTime'){
      params.sortField = 'submit_time'
    }else if(changeParams?.sorter.sortBy === 'submit_process'){
      params.sortField = 'submit_process'
    }
  }else{
    params.pageNum = 1
    params.sortField = 'update_time'
    params.sortOrder = 'DESC'
  }
  getList();
}
// 用户侧评估项目列表
onMounted(async() => {
  await getList();
})

const getList = () => {
    getAssessList(params)
      .then((res) => {
        if (res.code == 200) {
          tableData.value = res.data || {}
          // const list = []
          // res.data?.list?.forEach(element => {
          //   list.push(...element.child)
          // });
          // tableData.value.list = list
          tableData.value.list = res.data?.data
          console.log('tableData = ', tableData.value)
        } else {
        }
      }).finally(() => {
      });
  }
</script>
<style lang="scss" scoped>
</style>
